package tcp;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpIpServer {

    public static void main(String args[]){
        ServerSocket _ServerSocket = null;
        
        try{
            _ServerSocket =  new ServerSocket(7777);
            System.out.println("소켓서버가 기동되었습니다.");
            
        }catch(IOException e){
            e.getStackTrace();
        }
        
        //무한loop
        while(true){
            try{
                System.out.println("대기중...");
                
                Socket socket = _ServerSocket.accept();
                System.out.println("클라이언트에서 접속요청");
                
                OutputStream out = socket.getOutputStream();
                DataOutputStream dos = new DataOutputStream(out);
                
                dos.writeUTF("Test Write");
                System.out.println("데이터전송완료");
                
                dos.close();
                socket.close();
                
            }catch(IOException e){
                e.getStackTrace();
            }
        }
    }
}
